#!/usr/bin/perl -w

package XmlElementObj;

use strict;
use Exporter;

our @ISA=qw/Exporter/;
our @EXPORT=qw//;
our @EXPORT_OK=qw/new/;

sub new
{
	my $class=shift;
	my ($tagName)=shift;
	print "@_\n";
	my $self={};
	bless $self,$class;
	$self->Init($tagName);
	return $self;
}

sub Init
{
	my $this=shift;
	my $tagName=shift;
	$$this{'TagName'}=undef;#str
	$$this{'Text'}=undef;#str

	$$this{'Parent'}=0;#obj ref
	$$this{'Child'}=[];#empty array ref

	$$this{'Attribute'}={};#empty hash ref
	
	#setter
	$this->TagName($tagName);
}

sub Parent
{
	my ($this,$parentRef)=@_;
	if (defined($parentRef))
	{
		$$this{'Parent'}=$parentRef;
	}
	return $$this{'Parent'};
}

sub Child
{
	my ($this)=@_;
	return $$this{'Child'};
}

sub Attribute
{
	my ($this)=@_;
	return $$this{'Attribute'};
}

sub TagName
{
	my ($this,$tag)=@_;
	if (defined($tag))
	{
		$$this{'TagName'}=$tag;
	}
	return $$this{'TagName'};
}

sub Text
{
	my ($this,$text)=@_;
	if (defined($text))
	{
		$$this{'Text'}=$text;
	}
	return $$this{'Text'};
}

sub AddChild
{
	my ($this,$objRef)=@_;
	my $childArrayRef=$this->Child();
	push @$childArrayRef,$objRef;
	$$objRef->Parent(\$this);
}

1;

